<template>
	<el-main class="bg">
		<el-form label-position="right" :model="query" class="form p_4" label-width="120">
			<el-row>
				<el-col :xs="24" :sm="24" :lg="8">
					<el-form-item label="赛事名称">
						<el-input v-model="query.event_name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :lg="8">
					<el-form-item label="得分">
						<el-input v-model="query.score"></el-input>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="24" :lg="8">
					<el-form-item label="团队名称">
						<el-input v-model="query.team_name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :xs="24" :sm="10" :lg="8">
					<el-form-item>
						<el-button type="primary" @click="search()">查询</el-button>
						<el-button @click="reset()" style="margin-right: 74px;">重置</el-button>
						<router-link
							v-if="user_group == '管理员' || $check_action('/team_competition_score/table', 'add') || $check_action('/team_competition_score/view', 'add')"
							class="el-button el-button--default el-button--primary" to="./view?">添加
						</router-link>
						<el-button
							v-if="user_group == '管理员' || $check_action('/team_competition_score/table', 'del') || $check_action('/team_competition_score/view', 'del')"
							class="" type="danger" @click="delInfo()">删除</el-button>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<el-table :data="list" @selection-change="selectionChange" @sort-change="$sortChange" style="width: 100%"
			id="dataTable">
			<el-table-column fixed type="selection" tooltip-effect="dark" width="55">
			</el-table-column>
			<el-table-column prop="event_name" label="赛事名称" v-if="user_group == '管理员' || $check_field('get', 'event_name')"
				min-width="200">
			</el-table-column>
			<el-table-column prop="score" label="得分" v-if="user_group == '管理员' || $check_field('get', 'score')"
				min-width="200">
			</el-table-column>
			<!-- <el-table-column prop="judge_comment" label="评委评语"
				v-if="user_group == '管理员' || $check_field('get', 'judge_comment')" min-width="200">
			</el-table-column> -->
			<el-table-column prop="team_name" label="团队名称" v-if="user_group == '管理员' || $check_field('get', 'team_name')"
				min-width="200">
			</el-table-column>
			<el-table-column sortable prop="create_time" label="创建时间" min-width="200">
				<template slot-scope="scope">
					{{ $toTime(scope.row["create_time"], "yyyy-MM-dd hh:mm:ss") }}
				</template>
			</el-table-column>
			<el-table-column sortable prop="update_time" label="更新时间" min-width="200">
				<template slot-scope="scope">
					{{ $toTime(scope.row["update_time"], "yyyy-MM-dd hh:mm:ss") }}
				</template>
			</el-table-column>
			<el-table-column fixed="right" label="操作" min-width="120"
				v-if="user_group == '管理员' || $check_action('/team_competition_score/table', 'set') || $check_action('/team_competition_score/view', 'set') || $check_action('/team_competition_score/view', 'get')">
				<template slot-scope="scope">
					<router-link class="el-button el-button--small is-plain el-button--success" style="margin: 5px !important;"
						v-if="user_group == '管理员' || $check_action('/team_competition_score/table', 'set') || $check_action('/team_competition_score/view', 'set') || $check_action('/team_competition_score/view', 'get')"
						:to="'./view?' + field + '=' + scope.row[field]" size="small">
						<span>详情</span>
					</router-link>
				</template>
			</el-table-column>
		</el-table>
		<div class="mt text_center">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="query.page"
				:page-sizes="[7, 10, 30, 100]" :page-size="query.size" layout="total, sizes, prev, pager, next, jumper"
				:total="count">
			</el-pagination>
		</div>
	</el-main>
</template>
<script>
import mixin from "@/mixins/page.js";

export default {
	mixins: [mixin],
	data() {
		return {
			// 弹框
			showModal: false,
			url_get_list: "~/api/team_competition_score/get_list?like=0",
			url_del: "~/api/team_competition_score/del?",
			field: "team_score_id",
			query: {
				"size": 7,
				"page": 1,
				"event_name": "",
				"score": "",
				"team_name": "",
				"orderby": `create_time desc`
			},
			list: [],
		}
	},
	methods: {
		closeModal() {
			this.showModal = false;
		},
		get_list_before(param) {
			var user_group = this.user.user_group;
			if (user_group != "管理员") {
				switch (user_group) {
					case "普通用户":
						param["team_name"] = this.user.team_name;
						break;
				}
			}
			return param;
		},
		open_tip() {
			const h = this.$createElement;

			var message = "";
			var list = this.list;
			console.log(list);

			var ifs = [];
			for (var n = 0; n < ifs.length; n++) {
				var o = ifs[n];
				for (var i = 0; i < list.length; i++) {
					var lt = list[i];
					if (o.type == "数内") {
						if ((o.start || o.start === 0) && (o.end || o.end === 0)) {
							if (lt[o.factor] > o.start && lt[o.factor] < o.end) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.start || o.start === 0) {
							if (lt[o.factor] > o.start) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.end || o.end === 0) {
							if (lt[o.factor] < o.end) {
								o["idx"] = o["idx"] + 1;
							}
						}
					} else if (o.type == "数外") {
						if ((o.start || o.start === 0) && (o.end || o.end === 0)) {
							if (lt[o.factor] < o.start || lt[o.factor] > o.end) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.start || o.start === 0) {
							if (lt[o.factor] < o.start) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.end || o.end === 0) {
							if (lt[o.factor] > o.end) {
								o["idx"] = o["idx"] + 1;
							}
						}
					} else if (o.type == "日内") {
						if ((o.start) && (o.end)) {
							if (lt[o.factor] > o.start && lt[o.factor] < o.end) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.start) {
							if (lt[o.factor] < o.start) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.end) {
							if (lt[o.factor] > o.end) {
								o["idx"] = o["idx"] + 1;
							}
						}
					} else if (o.type == "日外") {
						if (o.start && o.end) {
							if (lt[o.factor] < o.start || lt[o.factor] > o.end) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.start) {
							if (lt[o.factor] < o.start) {
								o["idx"] = o["idx"] + 1;
							}
						} else if (o.end) {
							if (lt[o.factor] > o.end) {
								o["idx"] = o["idx"] + 1;
							}
						}
					}
				}

				if (o["idx"]) {
					message += o.title;
					if (o["type"] == "数内") {
						if (o.start || o.start === 0) {
							message += "大于" + o.start;
						}
						if ((o.start || o.start === 0) && (o.end || o.end === 0)) {
							message += "并且";
						}
						if (o.end || o.end === 0) {
							message += "小于" + o.end;
						}
					} else if (o["type"] == "数外") {
						if (o.start || o.start === 0) {
							message += "小于" + o.start;
						}
						if ((o.start || o.start === 0) || (o.end || o.end === 0)) {
							message += "或者";
						}
						if (o.end || o.end === 0) {
							message += "大于" + o.end;
						}
					} else if (o["type"] == "日内") {
						if (o.start) {
							message += "在" + o.start + "之后";
						}
						if (o.start && o.end) {
							message += "并且";
						}
						if (o.end) {
							message += "在" + o.end + "之前";
						}
					} else if (o["type"] == "日外") {
						if (o.start) {
							message += "在" + o.start + "之前";
						}
						if (o.start || o.end) {
							message += "或者";
						}
						if (o.end) {
							message += "在" + o.end + "之后";
						}
					}
					message += "的有" + o["idx"] + "条";
				}
			}

			if (message) {
				message += "，需要处理、请尽快处理。";
				this.showModal = true;
				// this.$notify({
				// 	title: '提醒',
				// 	dangerouslyUseHTMLString: true,
				// 	message: h('i', {
				// 		style: 'color: teal'
				// 	}, message)
				// });
			}
		},
	},
	created() {
		setTimeout(() => {
			this.open_tip();
		}, 1000)
	}
}
</script>
<style>
.bg {
	background: white;
}

.form.p_4 {
	padding: 1rem;
}

.mt {
	margin-top: 1rem;
}

.text_center {
	text-align: center;
}
</style>